package com.lxyk.service.imol;

import com.lxyk.mapper.UserMapper;
import com.lxyk.pojo.User;
import com.lxyk.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    /**
     * 查询所有
     * @return
     */
    public List<User> queryAll() {
        return userMapper.findAll();
    }
    /**
     * 新增
     * @param user
     * @return
     */
    public Integer addUser(User user) {
        return userMapper.add(user);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    public Integer deleteUser(Integer id) {
        return userMapper.deleteById(id);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    public User findUserById(Integer id) {
        return userMapper.findById(id);
    }

    /**
     * 修改
     * @param user
     * @return
     */
    public Integer updateUser(User user) {
        return userMapper.update(user);
    }

    /**
     * 条件查询
     * @param user
     * @return
     */
    public List<User> findByCode(User user) {
        //name 需要拼接%
       /* String name = user.getName();
        if (name != null && name != ""){
            user.setName("%"+name+"%");
        }*/
        return userMapper.findByCode(user);
    }
}
